package com.snail.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.snail.model.pojo.mall.BizProductReview;
import com.snail.model.vo.mall.ProductReviewVO;
import com.snail.result.Result;
import com.snail.service.IBizProductReviewService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
public class BizProductReviewController {
    @Resource
    private IBizProductReviewService bizProductReviewServiceImpl;

    @PostMapping("/add")
    public Result<?> addComment(@RequestBody BizProductReview bizProductReview) {
        bizProductReview.setDeleted(0);
        bizProductReviewServiceImpl.save(bizProductReview); // MyBatis-Plus 保存
        return Result.success("评论提交成功");
    }

    /**
     * 根据商品ID查询评论（含用户信息）
     * @param productId 商品ID
     * @return 评论列表
     */
    @GetMapping("/{productId}")
    public Result<List<ProductReviewVO>> getReviewsByProductId(@PathVariable("productId") Integer productId) {
        List<ProductReviewVO> reviews = bizProductReviewServiceImpl.getReviewsByProductId(productId);
        return Result.success(reviews); // 假设 Result 是统一响应类
    }

    /**
     * 根据评论ID（逻辑）删除评论
     * @param id 评论ID
     * @return 操作结果
     */
    @DeleteMapping("/{id}")
    public Result<?> deleteReview(@PathVariable("id") Integer id) {
        // 逻辑删除：将 deleted 字段设为 1
        boolean success = bizProductReviewServiceImpl.markDeletedById(id);
        return success ? Result.success("删除成功") : Result.failed("删除失败");
    }
}
